package com.horse.cloud.framework.mybatis.datasource;

import org.apache.ibatis.executor.statement.StatementHandler;
import org.apache.ibatis.plugin.*;
import org.springframework.context.annotation.Configuration;

import java.sql.Statement;
import java.util.Properties;

/**
 * @editor: intelliJ IDEA 16.1.3
 * @author bing.Pan
 * @e-Mail: 15923508369@163.com
 * @gmDate: 19/03/2018 20:15:下午8:15
 * @siDesc:
 */


@Intercepts({
        @Signature(type = StatementHandler.class, method = "batch", args = {Statement.class}),
        @Signature(type = StatementHandler.class, method = "update", args = {Statement.class}),
})
@Configuration
public class StatementHandlerInterceptor implements Interceptor {
    @Override
    public Object intercept(Invocation invocation) throws Throwable {

        DataSourceContextHolder.changeThreadLocalVal(true,false);
        return invocation.proceed();
    }

    @Override
    public Object plugin(Object target) {
        return Plugin.wrap(target, this);

    }

    @Override
    public void setProperties(Properties properties) {

    }
}
